//
//  HYEditUserApi.m
//  TJHYHardwareProduct
//
//  Created by JianWei Chen on 2018/1/23.
//  Copyright © 2018年 Kendama. All rights reserved.
//

#import "HYEditUserApi.h"

@implementation HYEditUserApi{
    NSDictionary *_dic;
}

-(id)initWithDic:(NSDictionary *)dic{
    if (self = [super init]) {
        _dic = dic;
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/user/edit_my_count";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (id)requestArgument {
    NSMutableDictionary *dic = [NSMutableDictionary getPubdic];
    [dic setValuesForKeysWithDictionary:_dic];
    
    if (_dic[@"old_password"]) {
        NSString* base64Text = [NSString encryptUseAES:_dic[@"old_password"] key:nil];
        [dic setObject:base64Text forKey:@"old_password"];
    }
    if (_dic[@"password"]) {
        NSString* base64Text = [NSString encryptUseAES:_dic[@"password"] key:nil];
        [dic setObject:base64Text forKey:@"password"];
    }
    if (_dic[@"com_password"]) {
        NSString* base64Text = [NSString encryptUseAES:_dic[@"com_password"] key:nil];
        [dic setObject:base64Text forKey:@"com_password"];
    }
    
    NSString *sign=[NSString getSign:dic];
    [dic setObject:sign forKey:@"sign"];
    return dic;
}


-(void)dealloc
{
    NSLog(@"%@ dealloc",[self class]);
}

+ (void)editPhone:(NSString *)phone old_password:(NSString *)old_password password:(NSString *)password com_password:(NSString *)com_password success:(void (^)(NSDictionary *))successBack fail:(void (^)(NSDictionary *))failBack
{
    NSMutableDictionary *requestDic = [[NSMutableDictionary alloc]init];
    if (phone)
    {
        [requestDic setValue:phone forKey:@"phone"];
    }
    if (old_password)
    {
        [requestDic setValue:old_password forKey:@"old_password"];
    }
    if (password)
    {
        [requestDic setValue:password forKey:@"password"];
    }
    if (com_password)
    {
        [requestDic setValue:com_password forKey:@"com_password"];
    }
    
    HYEditUserApi *api = [[HYEditUserApi alloc]initWithDic:requestDic];
    [api dtStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        if (successBack) {
            successBack(request.responseObject);
        }
    } failure:^(YTKBaseRequest * _Nonnull request) {
        if (failBack) {
            failBack(request.responseObject);
        }
    }];
}
@end
